package com.piz.dao.common;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

/**
 * Generic GenericDAO interface
 *
 * @author vschauhan
 *
 */
public interface PizHiber<T> {

    /**
     * Inserts row in the table
     *
     * @param obj
     */
    public void insert(T obj);

    /**
     * Deletes row from the table based on primary key
     *
     * @param obj
     */
    public void delete(T obj);

    /**
     * Updates row in the table based on primary key
     *
     * @param obj
     */
    public void update(T obj);

    /**
     * Gets row from the table when primary key is specified.
     *
     * @return the persistent instance, or null if not found
     */
    public T selectBasedOnPrimaryKey(Class<T> cls, T obj);

    /**
     * Returns list, when value of the fields based on whom selection is to be
     * done, are specified. </br> values can not be part of composite primary
     * key.</br> Rest fields are to be essentially kept null.
     *
     * @param obj
     * @return a List containing 0 or more persistent instances
     */
    public List<T> select(final T obj);

    /**
     * Saves if not exists ; or Updates if exists.
     *
     * @param obj
     */
    public void saveOrUpdate(T obj);

    /**
	 * Saves if not exists ; or Updates if exists.save
	 *
	 * @param Collection<T> col
	 */
    public void saveOrUpdateAll(Collection<T> col);
    /**
     * Selects all rows from a table.
     *
     * @param tablename
     */
    public List<T> selectAll(String tablename);

    /**
     * Executes native sql query to select; only one column is specified in
     * native SQL. Returns a list of objects.
     *
     * @param query
     * @return list
     */
     public List<Object> executeNativeSQLSingleColumn(final String query);

    /**
     * Executes native sql query to select; multiple columns are specified in
     * native SQL. Returns a list of object array.
     *
     * @param query
     * @return list
     */
     public List<Object[]> executeNativeSQLMultipleColumns(final String query);

    /**
     * Executes update, insert or delete SQL queries.
     *
     * @param query
     */
     public Integer executeNativeSQLUpdate(final String query);

    /**
     * Executes HQL query to update the table.
     *
     * @param hqlQuery
     */
    public void executeHQLUpdate(final String hqlQuery);

    /**
     * Executes HQL query to select data.
     *
     * @param hqlQuery
     */
    public List<T> executeHQL(final String hqlQuery);



    public List<T> findByCriteria(DetachedCriteria criteria);

    public List<T> findByDateRangeCriteria(Class<T> cls, String dateRangeColumn,
			Date startDate, Date endDate);

    public List<T> selectByDateRangeCriteria(
			String query,Date date);

	public T search(Class<T> cls, long Id);
	/**
	 * this method will return a criteria
	 * @param entityBean
	 * @return
	 */
	
	public DetachedCriteria getCriteria(Class<T> entityBean);

}
